//
//  CircleListViewController.m
//  RACExample
//
//  Created by 山刘 on 2020/6/3.
//  Copyright © 2020 山刘. All rights reserved.
//

#import "CircleListViewController.h"
#import "CircleListMainView.h"

@interface CircleListViewController ()
@property (nonatomic, strong) CircleListMainView *mainView;
@property(nonatomic, strong) CircleListMainViewModel *viewModel;
@end

@implementation CircleListViewController
#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    [self segInitViews];
    [self bindViewModel];
}
#pragma mark - init Views
-(void)segInitViews{
    [self.view addSubview:self.mainView];
}

#pragma mark - Layout
- (void)updateViewConstraints {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
    [super updateViewConstraints];
}

#pragma mark - RAC Data Binding
- (void)bindViewModel {
    // 点击 cell 跳转 Controller
    @weakify(self);
    [[self.viewModel.cellClickSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(CircleListMainViewCellViewModel*  _Nullable x) {
        @strongify(self);
        UIViewController *VC = [UIViewController new];
        VC.view.backgroundColor = [UIColor whiteColor];
        [self.navigationController pushViewController:VC animated:YES];
    }];
}

#pragma mark - getter
- (CircleListMainView *)mainView {
    if (!_mainView) {
        _mainView = [[CircleListMainView alloc] initWithViewModel:self.viewModel];
    }
    return _mainView;
}
-(CircleListMainViewModel *)viewModel{
    if (!_viewModel) {
        _viewModel = [[CircleListMainViewModel alloc]init];
    }
    return _viewModel;
}
@end
